﻿using Cinemachine;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;

public class SwitchBounds : MonoBehaviour
{
    private static SwitchBounds instance;
    public static SwitchBounds Instance => instance;
    //Cinemachine控制摄像机边界的组件
    private CinemachineConfiner confiner;
    private void Awake()
    {
        instance = this;
        confiner = GetComponent<CinemachineConfiner>();
    }

    private void Start()
    {
        SwtichBounds();
    }

    //切换摄像机边界碰撞器，在每次切换场景的时候调用它
    public void SwtichBounds()
    {
        confiner.m_BoundingShape2D = GameObject.FindWithTag("CinemachineBounds").GetComponent<PolygonCollider2D>();
        //调用此api清除缓存，避免意外情况
        confiner.InvalidatePathCache();
    }
}
